package flash.utils;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class OutputByteArray implements IOutputByteArray {
	
	private DataOutputStream output;

	public OutputByteArray(OutputStream output) throws IOException {
		this.output = new DataOutputStream(output);
	}
	
	public OutputByteArray(DataOutputStream output) {
		this.output = output;
	}

	@Override
	public void writeInt(int value) throws IOException {
		output.writeInt(value);
	}

	@Override
	public void writeDouble(double value) throws IOException {
		output.writeDouble(value);
	}

	@Override
	public void writeUTF(String value) throws IOException {
		if (value != null && value.length() > 0) {
			output.writeUTF(value);
		}
		/*
		byte[] bytes = value.getBytes("UTF-8");
		output.writeShort(bytes.length);
		output.write(bytes);
		*/
	}

	@Override
	public void writeShort(int value) throws IOException {
		output.writeShort(value);
	}

	@Override
	public void writeFloat(float value) throws IOException {
		output.writeFloat(value);
	}

	@Override
	public void writeBytes(byte[] value) throws IOException {
		assert value != null && value.length > 0;
		output.writeShort(value.length);
		output.write(value);
	}

}
